/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import rules.Rule;
import utils.GuiHelper;

/**
 *
 * @author Creator
 */
public class RulesPopUpMenu {

 

  public RulesPopUpMenu(){
      
  }

  public void createPopupMenu(MouseEvent event, ActionListener al, Collection cl )
   {

     if (event.isPopupTrigger()) {
       JPopupMenu popup = new JPopupMenu();

      GuiHelper.sortColOfRulesByWeight(cl);

       Iterator itr = cl.iterator();
       while (itr.hasNext()){
        Rule rl = (Rule)itr.next();
        JMenuItem mi = new JMenuItem(rl.getName()+" cost: "+rl.getWeight(rl.getQuadrat()));
        //mi.setToolTipText(rl.getPicName());
        //mi.setIcon( new ImageIcon("images/block64.gif"));
        mi.addActionListener(al);
        popup.add(mi);
       }
       //Menü anzeigen
       popup.show(
         event.getComponent(),
         event.getX(),
         event.getY()
       );
     }
   }

}
